<template>
  <div class="contain">
    <el-button type="danger"   @click="getTemplate"><el-icon class="el-icon--right"><Upload /></el-icon>下载模板</el-button>
 </div>
</template>

<script lang="ts" setup>
import { ref, onMounted ,reactive,watch} from 'vue'
import { exportTemplate} from "@/util/api";
import { useRouter } from "vue-router";
const router = useRouter();
const templateType = ref("")
const props = defineProps({
    templateType:String,
})
const getTemplate = async()=>{
       let res:any = await exportTemplate(templateType.value)
    //    console.log(res)
       handleFileError(res, templateType.value+'模板.xlsx')
}
const handleFileError = (blob:any, fileName:any)=>{
    var downloadUrl = window.URL.createObjectURL(blob);
    var a = document.createElement('a');
    a.style.display = 'none';
    a.href = downloadUrl;
    a.download = fileName;
    var event = new MouseEvent('click');
    a.dispatchEvent(event);
} 
watch(
    ()=>props,
    (newVal:any)=>{
        // console.log(newVal) 
        templateType.value = newVal.templateType
    },
    {deep:true,immediate:true}
    )
</script>

<style lang="scss" scoped>
.contain{
    display: inline-block;
}
</style>
